package com.hh.demo.service.impl;

import com.hh.demo.service.ITokenService;
import com.hh.demo.util.StrUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author 黄浩
 * @create 2022-07-28 22:42
 */
@Service
public class TokenServiceImpl implements ITokenService {
    @Resource
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public String createToken(String courseId) {
        Long userId = 1L;
        String token = StrUtils.getComplexRandomString(10);
        String key = courseId + ":" + userId;
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);
        return token;
    }
}
